﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using MeetingMinutesManager.Form;

namespace MeetingMinutesManager.Maintenance
{
    public partial class UserMaintenance : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            FormUtil.AuthenticateManager(Session, Response);
        }

        protected void grvUsers_OnRowCommand(object sender, GridViewCommandEventArgs e)
        {
            String commandName = e.CommandName;

            int index = Convert.ToInt32(e.CommandArgument);
            GridViewRow row = grvUsers.Rows[index];

            String ID = GridViewOperator.GetCellStringValue(grvUsers, row, "ID");
            String userName = GridViewOperator.GetCellStringValue(grvUsers, row, "usr_name");

            try
            {
                if (commandName.Equals("ApproveUser"))
                {
                    ResourceOperator.ApproveUser(ID);

                    ResourceOperator.SendNewUserApproval(userName);

                    Messenger.Show(Response, "User Approved.");
                }
            }
            catch (Exception ex)
            {
                Messenger.Show(Response, "Error: " + ex.Message);
                return;
            }

            grvUsers.DataBind();
        }
    }
}
